// https://www.lintcode.com/problem/compare-strings/
class Solution {
public:
    /**
     * @param A: A string
     * @param B: A string
     * @return: if string A contains all of the characters in B return true else return false
     */
     
    // The characters of B in A are not necessary continuous or ordered.

    bool compareStrings(string &A, string &B) {
        if (B.empty()) return true;
        if (A.empty()) return false;
        // map<char, int> record;
        // for (int i = 0; i < A.length(); ++i)
        // {
        //     if (record.find(A[i]) == record.end()) record[A[i]] = 0;
        //     else record[A[i]]++;
        // }
        // for (int i = 0; i < B.length(); ++i)
        // {
        //     if (record.find(B[i]) == record.end() || record[B[i]] < 0) return false;
        //     // 注意要判断个数
        //     record[B[i]]--;
        // }
        // return true;
        
        int c[26]; // 注意是int
        memset(c, 0, 26);
        for (int i = 0; i < A.length(); ++i)
        {
            c[A[i] - 'A']++; // 注意要减'A'
        }
        for (int i = 0; i < B.length(); ++i)
        {
            c[B[i] - 'A']--;
            if (c[B[i] - 'A'] < 0) return false;
        }
        return true;
    }
};